import { reactive, ref, watch } from 'vue';
// import { uni } from '@dcloudio/uni-app';
import { request } from '@/utils/request'
import { tokenManager } from '@/utils/tokenManager';

export function useLink() {
    const workflow_id = '7412069611123982348';

    async function getVideoLink(url) {
        return new Promise(async (resolve) => {


            try {
                const body = {
                    parameters: {
                        url
                    },
                    workflow_id,
                    is_async: false,
                };

                const response = await uni.request({
                    url: tokenManager.getCozeApiUrl(),
                    method: 'POST',
                    header: tokenManager.getHeaders(),
                    data: body,
                });

                if (response.statusCode !== 200) {
                    throw new Error(`HTTP error! status: ${response.statusCode}`);
                }

                const obj = response.data;

                console.log('obj', obj);
                const aim = JSON.parse(obj.data)
                console.log('aim', aim)
                resolve({
                    success: true,
                    message: aim,
                });

            } catch (error) {
                console.error('Error:', error);
                uni.showToast({ title: '请求失败', icon: 'none' });
                resolve({
                    success: false,
                    message: error.message,
                });
            }
        })
    }


    return {
        getVideoLink
    };
}